
#if 0
SM2:
p, a, b, gx, gy, n
FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF
FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC
28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93
32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7
BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0
FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123
#endif



#include "sec_common.h"
#include "e_os.h"
#include "hard.h"
#include <openssl/modes.h>
#include "types.h"
#include "ccp903_rsa1024.h"
#include "ccp903_rsa2048.h"
#include "ccp903_rsa4096.h"
#include "ccp903_sm2.h"
#include "sm2_speed.h"
#include "rsa_speed.h"
#include "rsa1024_data.h"//standard data
#include "rsa2048_data.h"//standard data
#include "sm2_data.h"//standard data
//#include "asymm_data.h"
//#define Debug
#define SPEED_TEST

int ccp903_fd;

int threadnum, cnt, op_test;
pthread_t thread[1024];
void *rsa1024_genkey_test(void *args) //speed
{
    int i;
    unsigned char rsa_e[128] = {0}, rsa_d[128] = {0}, rsa_n[128] = {0}, rsa_p[128] = {0}, rsa_q[128] = {0}, rsa_dp[128] = {0}, rsa_dq[128] = {0}, rsa_qInv[128] = {0};
    unsigned int rsa_e_len = 128, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len;
    for(i = 128; i > 128-3; i--)//pubkey 65535
    {
	((unsigned char *)rsa_e)[i-1] = key1_e[128 - i];
    }
  /*
    for(i = 0; i < 3; i++)//pubkey 65535
    {
	((unsigned char *)rsa_e)[i] = key1_e[i];
    }
   */
    for(i = 0; i< cnt; i++)
    {
	ccp903_rsa1024_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
    }
/*
#ifdef Debug
    printf("rsa1024_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
    printf("rsa1024_d: ");
    for(i = 0; i < rsa_d_len; i++)
    {
	printf("%x ",rsa_d[i]);
    }
    printf("\n");
    printf("rsa_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
    printf("rsa_p: ");
    for(i = 0; i < rsa_p_len; i++)
    {
	printf("%x ",rsa_p[i]);
    }
    printf("\n");
    printf("rsa_q: ");
    for(i = 0; i < rsa_q_len; i++)
    {
	printf("%x ",rsa_q[i]);
    }
    printf("\n");
#endif
*/
    pthread_exit(NULL);
}
void *rsa1024_encrypt_test(void *args)  //speed
{
	int i,ret = 0;
       //unsigned char rsa_e[128] = {0}, rsa_d[128] = {0}, rsa_n[128] = {0};
    	//unsigned int rsa_e_len = 128, rsa_d_len, rsa_n_len, rsa_c_len;
    	unsigned char rsa_e[128] = {0}, rsa_d[128] = {0}, rsa_n[128] = {0}, rsa_p[128] = {0}, rsa_q[128] = {0}, rsa_dp[128] = {0}, rsa_dq[128] = {0}, rsa_qInv[128] = {0};
    	unsigned int rsa_e_len = 128, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len;
    	unsigned char rsa_plain[P1024_LEN] = {0}, rsa_c[128] = {0};
#ifndef SPEED_TEST
    	for(i = 0; i < P1024_LEN; i++)
    	{
		rsa_plain[i] = rand();
    	}
/*
#ifdef Debug
    printf("rsa1024_plain: ");
    for(i = 0; i < P1024_LEN; i++)
    {
	printf("%x ",rsa_plain[i]);
    }
    printf("\n");
#endif
*/
   	for(i = 128; i > 128-3; i--)//pubkey 65535
    	{
		((unsigned char *)rsa_e)[i-1] = key1_e[128 - i];
    	}
  	/*
    	for(i = 0; i < 3; i++)//pubkey 65535
    	{
		((unsigned char *)rsa_e)[i] = key1_e[i];
    	}
	*/
//	ccp903_rsa1024_keygen(rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len);
	ccp903_rsa1024_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
#ifdef Debug
    printf("rsa1024_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
#endif
    	for(i = 0; i< cnt; i++)
    	{
		 ccp903_rsa1024_encrpy(ccp903_fd, rsa_e, rsa_e_len, rsa_n, rsa_n_len, rsa_plain, P1024_LEN, rsa_c, &rsa_c_len);
        }
#ifdef Debug
    printf("rsa1024_c: ");
    for(i = 0; i < rsa_c_len; i++)
    {
	printf("%x ",rsa_c[i]);
    }
    printf("\n");
#endif
#else
    	for(i = 0; i< cnt; i++)
    	{
		 ret = ccp903_rsa1024_encrpy(ccp903_fd, Rsa1024_e, 128, Rsa1024_n, 128, Rsa1024_plain, 128, rsa_c, &rsa_c_len);
		  if(ret != 1)
			{
				printf("rsa1024 encrpy error\n");
			}
        }

#endif

}
void *rsa1024_decrypt_crt_test(void *args)//speed
{
	int i,ret = 0;
    	unsigned char rsa_e[128] = {0}, rsa_d[128] = {0}, rsa_n[128] = {0}, rsa_p[128] = {0}, rsa_q[128] = {0}, rsa_dp[128] = {0}, rsa_dq[128] = {0}, rsa_qInv[128] = {0};
    	unsigned int rsa_e_len = 128, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len, rsa_plain_dec_len;
    	unsigned char rsa_plain[P1024_LEN] = {0}, rsa_c[128] = {0},rsa_plain_dec[128] = {0};
#ifndef SPEED_TEST
    	for(i = 0; i < P1024_LEN; i++)
    	{
		rsa_plain[i] = rand();
    	}
#ifdef Debug
    printf("unsigned char Rsa1024_plain[128] = { \n ");
    for(i = 0; i < P1024_LEN; i++)
    {
	printf("0x%x,",rsa_plain[i]);
    }
    printf("\n};\n");
#endif
    	for(i = 128; i > 128-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[128 - i];
    	}
#ifdef Debug
    printf("unsigned char Rsa1024_e[128] = { \n ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("0x%x,",rsa_e[i]);
    }
    printf("\n};\n");
#endif
	//	ccp903_rsa1024_keygen(rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len);
	ccp903_rsa1024_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
	ccp903_rsa1024_encrpy(ccp903_fd, rsa_e, rsa_e_len, rsa_n, rsa_n_len, rsa_plain, P1024_LEN, rsa_c, &rsa_c_len);
#ifdef Debug
    printf("unsigned char Rsa1024_d[128] = { \n ");
    for(i = 0; i < rsa_d_len; i++)
    {
	printf("0x%x,",rsa_d[i]);
    }
    printf("\n};\n");
    printf("unsigned char Rsa1024_n[128] = {\n ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("0x%x,",rsa_n[i]);
    }
    printf("\n};\n");
    printf("unsigned char Rsa1024_p[128] = {\n ");
    for(i = 0; i < rsa_p_len; i++)
    {
	printf("0x%x,",rsa_p[i]);
    }
    printf("\n};\n");
    printf("unsigned char Rsa1024_q[128] = {\n ");
    for(i = 0; i < rsa_q_len; i++)
    {
	printf("0x%x,",rsa_q[i]);
    }
    printf("\n};\n");
    printf("unsigned char Rsa1024_dp[128] = {\n ");
    for(i = 0; i < rsa_dp_len; i++)
    {
	printf("0x%x,",rsa_dp[i]);
    }
    printf("\n};\n");
    printf("unsigned char Rsa1024_dq[128] = {\n ");
    for(i = 0; i < rsa_dq_len; i++)
    {
	printf("0x%x,",rsa_dq[i]);
    }
    printf("\n};\n");
    printf("unsigned char Rsa1024_qInv[128] = {\n ");
    for(i = 0; i < rsa_qInv_len; i++)
    {
	printf("0x%x,",rsa_qInv[i]);
    }
    printf("\n};\n");
    printf("unsigned char Rsa1024_c[128] = {\n ");
    for(i = 0; i < rsa_c_len; i++)
    {
	printf("0x%x,",rsa_c[i]);
    }
    printf("\n};\n");
#endif

        for(i = 0; i< cnt; i++)
	{
		ccp903_rsa1024_decrypt_crt(ccp903_fd, rsa_c, rsa_c_len, rsa_n, rsa_n_len, rsa_p, rsa_p_len, rsa_q, rsa_q_len, rsa_dp, rsa_dp_len, rsa_dq, rsa_dq_len, rsa_qInv, rsa_qInv_len, rsa_plain_dec, &rsa_plain_dec_len);
        }
#ifdef Debug
    printf("unsigned char Rsa1024_plain_dec[128] = {\n ");
    for(i = 0; i < rsa_plain_dec_len; i++)
    {
	printf("0x%x,",rsa_plain_dec[i]);
    }
    printf("\n};\n");
#endif
#else
	for(i = 0; i< cnt; i++)
	{
		ret = ccp903_rsa1024_decrypt_crt(ccp903_fd, Rsa1024_c, 128, Rsa1024_n, 128, Rsa1024_p, 128, Rsa1024_q, 128, Rsa1024_dp, 128, Rsa1024_dq, 128, Rsa1024_qInv, 128, rsa_plain_dec, &rsa_plain_dec_len);
        	if(ret != 1)
		{
			printf("rsa1024_decrypt_crt_error\n");
		}
	}
#endif

}
void *rsa1024_decrypt_nocrt_test(void *args)
{
	int i, ret = 0;
    	unsigned char rsa_e[128] = {0}, rsa_d[128] = {0}, rsa_n[128] = {0}, rsa_p[128] = {0}, rsa_q[128] = {0}, rsa_dp[128] = {0}, rsa_dq[128] = {0}, rsa_qInv[128] = {0};
    	unsigned int rsa_e_len = 128, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len, rsa_plain_dec_len;
    	unsigned char rsa_plain[P1024_LEN] = {0}, rsa_c[128] = {0},rsa_plain_dec[128] = {0};
#ifndef SPEED_TEST
    	for(i = 0; i < P1024_LEN; i++)
    	{
		rsa_plain[i] = i;
    	}
#ifdef Debug
    printf("rsa1024_plain: ");
    for(i = 0; i < P1024_LEN; i++)
    {
	printf("%x ",rsa_plain[i]);
    }
    printf("\n");
#endif
    	for(i = 128; i > 128-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[128 - i];
    	}
#ifdef Debug
    printf("rsa1024_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
	//	ccp903_rsa1024_keygen(rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len);
	ccp903_rsa1024_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
	ccp903_rsa1024_encrpy(ccp903_fd, rsa_e, rsa_e_len, rsa_n, rsa_n_len, rsa_plain, P1024_LEN, rsa_c, &rsa_c_len);
#ifdef Debug
    printf("rsa1024_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
    printf("rsa1024_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
    printf("rsa1024_c: ");
    for(i = 0; i < rsa_c_len; i++)
    {
	printf("%x ",rsa_c[i]);
    }
    printf("\n");
#endif
    	for(i = 0; i< cnt; i++)
	{
		ccp903_rsa1024_decrypt_nocrt(ccp903_fd, rsa_c, rsa_c_len, rsa_n, rsa_n_len, rsa_d, rsa_d_len, rsa_plain_dec, &rsa_plain_dec_len);
        }
#ifdef Debug
    printf("rsa1024_plain_dec: ");
    for(i = 0; i < rsa_plain_dec_len; i++)
    {
	printf("%x ",rsa_plain_dec[i]);
    }
    printf("\n");
#endif
#else
    	for(i = 0; i< cnt; i++)
	{
		ret = ccp903_rsa1024_decrypt_nocrt(ccp903_fd, Rsa1024_c, 128, Rsa1024_n, 128, Rsa1024_d, 128, rsa_plain_dec, &rsa_plain_dec_len);
		if(ret != 1)
		{
			printf("decrypt nocrt error\n");
		}
        }

#endif
}
void *rsa1024_sign_crt_test(void *args)
{
	int i,ret = 0;
    	unsigned char rsa_e[128] = {0}, rsa_d[128] = {0}, rsa_n[128] = {0}, rsa_p[128] = {0}, rsa_q[128] = {0}, rsa_dp[128] = {0}, rsa_dq[128] = {0}, rsa_qInv[128] = {0};
    	unsigned int rsa_e_len = 128, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len, rsa_sign_len;
    	unsigned char rsa_plain[P1024_LEN] = {0}, rsa_sign[128] = {0};
#ifndef SPEED_TEST
 	for(i = 0; i < P1024_LEN; i++)
    	{
		rsa_plain[i] = i;
    	}
#ifdef Debug
    printf("rsa1024_plain: ");
    for(i = 0; i < P1024_LEN; i++)
    {
	printf("%x ",rsa_plain[i]);
    }
    printf("\n");
#endif
    	for(i = 128; i > 128-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[128 - i];
    	}
#ifdef Debug
    printf("rsa1024_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
	//	ccp903_rsa1024_keygen(rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len);
	ccp903_rsa1024_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
#ifdef Debug
    printf("rsa1024_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
    printf("rsa1024_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
    	for(i = 0; i< cnt; i++)
	{
		ccp903_rsa1024_sign_crt(ccp903_fd, rsa_plain, P1024_LEN, rsa_n, rsa_n_len, rsa_p, rsa_p_len, rsa_q, rsa_q_len, rsa_dp, rsa_dp_len, rsa_dq, rsa_dq_len, rsa_qInv, rsa_qInv_len, rsa_sign, &rsa_sign_len);
        }
#ifdef Debug
    printf("rsa1024_sign: ");
    for(i = 0; i < rsa_sign_len; i++)
    {
	printf("%x ",rsa_sign[i]);
    }
    printf("\n");
#endif
#else
    	for(i = 0; i< cnt; i++)
	{
		ret = ccp903_rsa1024_sign_crt(ccp903_fd, Rsa1024_plain, 128, Rsa1024_n, 128, Rsa1024_p, 128, Rsa1024_q, 128, Rsa1024_dp, 128, Rsa1024_dq, 128, Rsa1024_qInv, 128, rsa_sign, &rsa_sign_len);
        }
	if(ret != 1)
	{
		printf("rsa1024_sign_crt_error\n");
	}
#endif
}
void *rsa1024_verify_test(void *args)
{
	int i,ret = 0;
    	unsigned char rsa_e[128] = {0}, rsa_d[128] = {0}, rsa_n[128] = {0}, rsa_p[128] = {0}, rsa_q[128] = {0}, rsa_dp[128] = {0}, rsa_dq[128] = {0}, rsa_qInv[128] = {0};
    	unsigned int rsa_e_len = 128, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len, rsa_sign_len, rsa_ver_plain_len;
    	unsigned char rsa_plain[P1024_LEN] = {0}, rsa_sign[128] = {0}, rsa_ver_plain[128] = {0};
#ifndef SPEED_TEST
    	for(i = 0; i < P1024_LEN; i++)
    	{
		rsa_plain[i] = i;
    	}
#ifdef Debug
    printf("rsa1024_plain: ");
    for(i = 0; i < P1024_LEN; i++)
    {
	printf("%x ",rsa_plain[i]);
    }
    printf("\n");
#endif
    	for(i = 128; i > 128-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[128 - i];
    	}
#ifdef Debug
    printf("rsa1024_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
	//	ccp903_rsa1024_keygen(rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len);
	ccp903_rsa1024_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
#ifdef Debug
    printf("rsa1024_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
    printf("rsa1024_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
    ccp903_rsa1024_sign_crt(ccp903_fd, rsa_plain, P1024_LEN, rsa_n, rsa_n_len, rsa_p, rsa_p_len, rsa_q, rsa_q_len, rsa_dp, rsa_dp_len, rsa_dq, rsa_dq_len, rsa_qInv, rsa_qInv_len, rsa_sign, &rsa_sign_len);
#ifdef Debug
    printf("rsa1024_sign: ");
    for(i = 0; i < rsa_sign_len; i++)
    {
	printf("%x ",rsa_sign[i]);
    }
    printf("\n");
#endif
    	for(i = 0; i< cnt; i++)
	{
		ccp903_rsa1024_verify(ccp903_fd, rsa_plain, P1024_LEN, rsa_e, rsa_e_len, rsa_n, rsa_n_len, rsa_sign, rsa_sign_len, rsa_ver_plain, &rsa_ver_plain_len);
        }
#ifdef Debug
    printf("rsa1024_ver_plain: ");
    for(i = 0; i < rsa_ver_plain_len; i++)
    {
	printf("%x ",rsa_ver_plain[i]);
    }
    printf("\n");
#endif
    if(!memcmp(rsa_plain,rsa_ver_plain,rsa_ver_plain_len))
    {
	printf("rsa1024 verify success!!\n");
    }
    else
    {
	printf("rsa1024 verify failed!!\n");
    }
#else
    	for(i = 128; i > 128-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[128 - i];
    	}
    	for(i = 0; i< cnt; i++)
	{
		ret = ccp903_rsa1024_verify(ccp903_fd, Rsa1024_plain, 128, Rsa1024_e, 128, Rsa1024_n, 128, Rsa1024_c, 128, rsa_ver_plain, &rsa_ver_plain_len);
        }
	if(ret != 1)
	{
		printf("rsa1024_verify error");
	}
#endif

}
void *rsa1024_verify_sign_nocrt_test(void *args)
{
	int i, ret = 0;
    	unsigned char rsa_e[128] = {0}, rsa_d[128] = {0}, rsa_n[128] = {0}, rsa_p[128] = {0}, rsa_q[128] = {0}, rsa_dp[128] = {0}, rsa_dq[128] = {0}, rsa_qInv[128] = {0};
    	unsigned int rsa_e_len = 128, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len, rsa_sign_len, rsa_ver_plain_len;
    	unsigned char rsa_plain[P1024_LEN] = {0}, rsa_sign[128] = {0}, rsa_ver_plain[128] = {0};
#ifndef SPEED_TEST
    	for(i = 0; i < P1024_LEN; i++)
    	{
		rsa_plain[i] = i;
    	}
#ifdef Debug
    printf("rsa1024_plain: ");
    for(i = 0; i < P1024_LEN; i++)
    {
	printf("%x ",rsa_plain[i]);
    }
    printf("\n");
#endif
    	for(i = 128; i > 128-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[128 - i];
    	}
#ifdef Debug
    printf("rsa1024_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
	//	ccp903_rsa1024_keygen(rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len);
	ccp903_rsa1024_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
#ifdef Debug
    printf("rsa1024_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
    printf("rsa1024_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
    ccp903_rsa1024_sign_nocrt(ccp903_fd, rsa_plain, P1024_LEN, rsa_n, rsa_n_len, rsa_d, rsa_d_len, rsa_sign, &rsa_sign_len);
#ifdef Debug
    printf("rsa1024_sign: ");
    for(i = 0; i < rsa_sign_len; i++)
    {
	printf("%x ",rsa_sign[i]);
    }
    printf("\n");
#endif
    	for(i = 0; i< cnt; i++)
	{
		ccp903_rsa1024_verify(ccp903_fd, rsa_plain, P1024_LEN, rsa_e, rsa_e_len, rsa_n, rsa_n_len, rsa_sign, rsa_sign_len, rsa_ver_plain, &rsa_ver_plain_len);
        }
#ifdef Debug
    printf("rsa1024_ver_plain: ");
    for(i = 0; i < rsa_ver_plain_len; i++)
    {
	printf("%x ",rsa_ver_plain[i]);
    }
    printf("\n");
#endif
    if(!memcmp(rsa_plain,rsa_ver_plain,rsa_ver_plain_len))
    {
	printf("rsa1024 verify success!!\n");
    }
    else
    {
	printf("rsa1024 verify failed!!\n");
    }
#else
    	for(i = 0; i< cnt; i++)
	{
		ret = ccp903_rsa1024_verify(ccp903_fd, Rsa1024_plain, 128, Rsa1024_e, 128, Rsa1024_n, 128, Rsa1024_c, 128, rsa_ver_plain, &rsa_ver_plain_len);
        }
	if(ret != 1)
	{
		printf("rsa1024_verify_error\n");
	}

#endif

}
void *rsa2048_genkey_test(void *args)
{
    int i,ret = 0;
    unsigned char rsa_e[256] = {0}, rsa_d[256] = {0}, rsa_n[256] = {0}, rsa_p[256] = {0}, rsa_q[256] = {0}, rsa_dp[256] = {0}, rsa_dq[256] = {0}, rsa_qInv[256] = {0};
    unsigned int rsa_e_len = 256, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len;
    for(i = 256; i > 256-3; i--)//pubkey 65535
    {
	((unsigned char *)rsa_e)[i-1] = key1_e[256 - i];
    }
    for(i = 0; i< cnt; i++)
    {
	ccp903_rsa2048_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
    }
/*
#ifdef Debug
    printf("rsa2048_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
    printf("rsa2048_d: ");
    for(i = 0; i < rsa_d_len; i++)
    {
	printf("%x ",rsa_d[i]);
    }
    printf("\n");
    printf("rsa2048_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
    printf("rsa2048_p: ");
    for(i = 0; i < rsa_p_len; i++)
    {
	printf("%x ",rsa_p[i]);
    }
    printf("\n");
    printf("rsa2048_q: ");
    for(i = 0; i < rsa_q_len; i++)
    {
	printf("%x ",rsa_q[i]);
    }
    printf("\n");
    printf("rsa2048_dp: ");
    for(i = 0; i < rsa_dp_len; i++)
    {
	printf("%x ",rsa_dp[i]);
    }
    printf("\n");
    printf("rsa2048_dq: ");
    for(i = 0; i < rsa_dq_len; i++)
    {
	printf("%x ",rsa_dq[i]);
    }
    printf("\n");
#endif
*/
    pthread_exit(NULL);
}
void *rsa2048_encrypt_test(void *args)
{
	int i, ret = 0;
    	unsigned char rsa_e[256] = {0}, rsa_d[256] = {0}, rsa_n[256] = {0}, rsa_p[256] = {0}, rsa_q[256] = {0}, rsa_dp[256] = {0}, rsa_dq[256] = {0}, rsa_qInv[256] = {0};
    	unsigned int rsa_e_len = 256, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len;
    	unsigned char rsa_plain[P2048_LEN] = {0}, rsa_c[256] = {0};
#ifndef SPEED_TEST
    	for(i = 0; i < P2048_LEN; i++)
    	{
		rsa_plain[i] = rand();
    	}
#ifdef Debug
    printf("rsa2048_plain: ");
    for(i = 0; i < P2048_LEN; i++)
    {
	printf("%x ",rsa_plain[i]);
    }
    printf("\n");
#endif
   	for(i = 256; i > 256-3; i--)//pubkey 65535
    	{
		((unsigned char *)rsa_e)[i-1] = key1_e[256 - i];
    	}
	ccp903_rsa2048_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
#ifdef Debug
    printf("rsa2048_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
#endif
    	for(i = 0; i< cnt; i++)
    	{
		 ccp903_rsa2048_encrpy(ccp903_fd, rsa_e, rsa_e_len, rsa_n, rsa_n_len, rsa_plain, P2048_LEN, rsa_c, &rsa_c_len);
        }
#ifdef Debug
    printf("rsa2048_c: ");
    for(i = 0; i < rsa_c_len; i++)
    {
	printf("%x ",rsa_c[i]);
    }
    printf("\n");
#endif
#else
   	for(i = 256; i > 256-3; i--)//pubkey 65535
    	{
		((unsigned char *)rsa_e)[i-1] = key1_e[256 - i];
    	}
    	for(i = 0; i< cnt; i++)
    	{
		 ret = ccp903_rsa2048_encrpy(ccp903_fd, Rsa2048_e, 256, Rsa2048_n, 256, Rsa2048_plain, 256, rsa_c, &rsa_c_len);
		if(ret != 1)
		{
			printf("rsa2048_encpry error\n");
		}
        }
#endif
}
void *rsa2048_decrypt_crt_test(void *args)
{
	int i, ret = 0;
    	unsigned char rsa_e[256] = {0}, rsa_d[256] = {0}, rsa_n[256] = {0}, rsa_p[256] = {0}, rsa_q[256] = {0}, rsa_dp[256] = {0}, rsa_dq[256] = {0}, rsa_qInv[256] = {0};
    	unsigned int rsa_e_len = 256, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len, rsa_plain_dec_len;
    	unsigned char rsa_plain[P2048_LEN] = {0}, rsa_c[256] = {0},rsa_plain_dec[256] = {0};
#ifndef SPEED_TEST
    	for(i = 0; i < P2048_LEN; i++)
    	{
		rsa_plain[i] = rand();
    	}
#ifdef Debug
    printf("unsigned char Rsa2048_plain[256] = { \n");
    for(i = 0; i < P2048_LEN; i++)
    {
	printf("0x%x,",rsa_plain[i]);
    }
    printf("\n};\n");
#endif
    	for(i = 256; i > 256-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[256 - i];
    	}
#ifdef Debug
    printf("unsigned char Rsa2048_e[256] = { \n");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("0x%x,",rsa_e[i]);
    }
    printf("\n};\n");
#endif
	ccp903_rsa2048_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
#ifdef Debug
    printf("unsigned char Rsa2048_d[256] = { \n ");
    for(i = 0; i < rsa_d_len; i++)
    {
	printf("0x%x,",rsa_d[i]);
    }
    printf("\n};\n");
    printf("unsigned char Rsa2048_n[256] = {\n ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("0x%x,",rsa_n[i]);
    }
    printf("\n};\n");
    printf("unsigned char Rsa2048_p[256] = {\n ");
    for(i = 0; i < rsa_p_len; i++)
    {
	printf("0x%x,",rsa_p[i]);
    }
    printf("\n};\n");
    printf("unsigned char Rsa2048_q[256] = {\n ");
    for(i = 0; i < rsa_q_len; i++)
    {
	printf("0x%x,",rsa_q[i]);
    }
    printf("\n};\n");
    printf("unsigned char Rsa2048_dp[256] = {\n ");
    for(i = 0; i < rsa_dp_len; i++)
    {
	printf("0x%x,",rsa_dp[i]);
    }
    printf("\n};\n");
    printf("unsigned char Rsa2048_dq[256] = {\n ");
    for(i = 0; i < rsa_dq_len; i++)
    {
	printf("0x%x,",rsa_dq[i]);
    }
    printf("\n};\n");
    printf("unsigned char Rsa2048_qInv[256] = {\n ");
    for(i = 0; i < rsa_qInv_len; i++)
    {
	printf("0x%x,",rsa_qInv[i]);
    }
    printf("\n};\n");
#endif
	ccp903_rsa2048_encrpy(ccp903_fd, rsa_e, rsa_e_len, rsa_n, rsa_n_len, rsa_plain, P2048_LEN, rsa_c, &rsa_c_len);
#ifdef Debug
    printf("unsigned char Rsa2048_c[256] = { \n");
    for(i = 0; i < rsa_c_len; i++)
    {
	printf("0x%x,",rsa_c[i]);
    }
    printf("\n};\n");
#endif
    	for(i = 0; i< cnt; i++)
	{
		ccp903_rsa2048_decrypt_crt(ccp903_fd, rsa_c, rsa_c_len, rsa_n, rsa_n_len, rsa_p, rsa_p_len, rsa_q, rsa_q_len, rsa_dp, rsa_dp_len, rsa_dq, rsa_dq_len, rsa_qInv, rsa_qInv_len, rsa_plain_dec, &rsa_plain_dec_len);
        }
#ifdef Debug
    printf("unsigned char Rsa2048_plain_dec = {\n ");
    for(i = 0; i < rsa_plain_dec_len; i++)
    {
	printf("0x%x,",rsa_plain_dec[i]);
    }
    printf("\n};\n");
#endif
#ifdef Debug
    if(!memcmp(rsa_plain,rsa_plain_dec,rsa_plain_dec_len))
    {
	printf("rsa2048 dec success!!\n");
    }
    else
    {
	printf("rsa2048 dec failed!!\n");
    }
#endif
#else
    	for(i = 0; i< cnt; i++)
	{
		ret = ccp903_rsa2048_decrypt_crt(ccp903_fd, Rsa2048_e, 256, Rsa2048_n, 256, Rsa2048_p, 256, Rsa2048_q, 256, Rsa2048_dp, 256, Rsa2048_dq, 256, Rsa2048_qInv, 256, rsa_plain_dec, &rsa_plain_dec_len);
        	if(ret != 1)
		{
			printf("rsa2048_decrypt_crt error\n");
		}
		//printf("rsa2048_decrypt_crt i = %d\n",i);
	}
#endif
}
void *rsa2048_sign_crt_test(void *args)
{
	int i, ret = 0;
    	unsigned char rsa_e[256] = {0}, rsa_d[256] = {0}, rsa_n[256] = {0}, rsa_p[256] = {0}, rsa_q[256] = {0}, rsa_dp[256] = {0}, rsa_dq[256] = {0}, rsa_qInv[256] = {0};
    	unsigned int rsa_e_len = 256, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len, rsa_sign_len;
    	unsigned char rsa_plain[P2048_LEN] = {0}, rsa_sign[256] = {0};
#ifndef SPEED_TEST
    	for(i = 0; i < P2048_LEN; i++)
    	{
		rsa_plain[i] = i;
    	}
#ifdef Debug
    printf("rsa2048_plain: ");
    for(i = 0; i < P2048_LEN; i++)
    {
	printf("%x ",rsa_plain[i]);
    }
    printf("\n");
#endif
    	for(i = 256; i > 256-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[256 - i];
    	}
#ifdef Debug
    printf("rsa2048_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
	ccp903_rsa2048_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
#ifdef Debug
    printf("rsa2048_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
    printf("rsa2048_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
    	for(i = 0; i< cnt; i++)
	{
		ccp903_rsa2048_sign_crt(ccp903_fd, rsa_plain, P2048_LEN, rsa_n, rsa_n_len, rsa_p, rsa_p_len, rsa_q, rsa_q_len, rsa_dp, rsa_dp_len, rsa_dq, rsa_dq_len, rsa_qInv, rsa_qInv_len, rsa_sign, &rsa_sign_len);
        }
#ifdef Debug
    printf("rsa2048_sign: ");
    for(i = 0; i < rsa_sign_len; i++)
    {
	printf("%x ",rsa_sign[i]);
    }
    printf("\n");
#endif
#else
    	for(i = 0; i< cnt; i++)
	{
		ret = ccp903_rsa2048_sign_crt(ccp903_fd, Rsa2048_c, 256, Rsa2048_n, 256, Rsa2048_p, 256, Rsa2048_q, 256, Rsa2048_dp, 256, Rsa2048_dq, 256, Rsa2048_qInv, 256, rsa_sign, &rsa_sign_len);
		if(ret != 1)
		{
			printf("rsa2048_sign_crt error\n");
		}
        }

#endif
}
void *rsa2048_verify_test(void *args)
{
	int i, ret = 0;
    	unsigned char rsa_e[256] = {0}, rsa_d[256] = {0}, rsa_n[256] = {0}, rsa_p[256] = {0}, rsa_q[256] = {0}, rsa_dp[256] = {0}, rsa_dq[256] = {0}, rsa_qInv[256] = {0};
    	unsigned int rsa_e_len = 256, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len, rsa_sign_len, rsa_ver_plain_len;
    	unsigned char rsa_plain[P2048_LEN] = {0}, rsa_sign[256] = {0}, rsa_ver_plain[256] = {0};
#ifndef SPEED_TEST
 	for(i = 0; i < P2048_LEN; i++)
    	{
		rsa_plain[i] = i;
    	}
#ifdef Debug
    printf("rsa2048_plain: ");
    for(i = 0; i < P2048_LEN; i++)
    {
	printf("%x ",rsa_plain[i]);
    }
    printf("\n");
#endif
    	for(i = 256; i > 256-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[256 - i];
    	}
#ifdef Debug
    printf("rsa2048_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
	ccp903_rsa2048_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
#ifdef Debug
    printf("rsa2048_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
    printf("rsa2048_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
    ccp903_rsa2048_sign_crt(ccp903_fd, rsa_plain, P2048_LEN, rsa_n, rsa_n_len, rsa_p, rsa_p_len, rsa_q, rsa_q_len, rsa_dp, rsa_dp_len, rsa_dq, rsa_dq_len, rsa_qInv, rsa_qInv_len, rsa_sign, &rsa_sign_len);
#ifdef Debug
    printf("rsa2048_sign: ");
    for(i = 0; i < rsa_sign_len; i++)
    {
	printf("%x ",rsa_sign[i]);
    }
    printf("\n");
#endif
    	for(i = 0; i< cnt; i++)
	{
		ccp903_rsa2048_verify(ccp903_fd, rsa_plain, P2048_LEN, rsa_e, rsa_e_len, rsa_n, rsa_n_len, rsa_sign, rsa_sign_len, rsa_ver_plain, &rsa_ver_plain_len);
        }
#ifdef Debug
    printf("rsa2048_ver_plain: ");
    for(i = 0; i < rsa_ver_plain_len; i++)
    {
	printf("%x ",rsa_ver_plain[i]);
    }
    printf("\n");
#endif
    if(!memcmp(rsa_plain,rsa_ver_plain,rsa_ver_plain_len))
    {
	printf("rsa2048 verify success!!\n");
    }
    else
    {
	printf("rsa2048 verify failed!!\n");
    }
#else

    	for(i = 0; i< cnt; i++)
	{
		ret = ccp903_rsa2048_verify(ccp903_fd, Rsa2048_plain, 256, Rsa2048_e, 256, Rsa2048_n, 256, Rsa2048_c, 256, rsa_ver_plain, &rsa_ver_plain_len);
		if(ret != 1)
		{
			printf("rsa2048_verify error\n");
		}
        }

#endif
}
void *rsa2048_decrypt_nocrt_test(void *args)
{
	int i, ret = 0;
    	unsigned char rsa_e[256] = {0}, rsa_d[256] = {0}, rsa_n[256] = {0}, rsa_p[256] = {0}, rsa_q[256] = {0}, rsa_dp[256] = {0}, rsa_dq[256] = {0}, rsa_qInv[256] = {0};
    	unsigned int rsa_e_len = 256, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len, rsa_plain_dec_len;
    	unsigned char rsa_plain[P2048_LEN] = {0}, rsa_c[256] = {0},rsa_plain_dec[256] = {0};
#ifndef SPEED_TEST
    	for(i = 0; i < P2048_LEN; i++)
    	{
		rsa_plain[i] = i;
    	}
#ifdef Debug
    printf("rsa2048_plain: ");
    for(i = 0; i < P2048_LEN; i++)
    {
	printf("%x ",rsa_plain[i]);
    }
    printf("\n");
#endif
    	for(i = 256; i > 256-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[256 - i];
    	}
#ifdef Debug
    printf("rsa2048_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
	ccp903_rsa2048_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
	ccp903_rsa2048_encrpy(ccp903_fd, rsa_e, rsa_e_len, rsa_n, rsa_n_len, rsa_plain, P2048_LEN, rsa_c, &rsa_c_len);
#ifdef Debug
    printf("rsa2048_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
    printf("rsa2048_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
    printf("rsa2048_c: ");
    for(i = 0; i < rsa_c_len; i++)
    {
	printf("%x ",rsa_c[i]);
    }
    printf("\n");
#endif
    	for(i = 0; i< cnt; i++)
	{
		ccp903_rsa2048_decrypt_nocrt(ccp903_fd, rsa_c, rsa_c_len, rsa_n, rsa_n_len, rsa_d, rsa_d_len, rsa_plain_dec, &rsa_plain_dec_len);
        }
#ifdef Debug
    printf("rsa2048_plain_dec: ");
    for(i = 0; i < rsa_plain_dec_len; i++)
    {
	printf("%x ",rsa_plain_dec[i]);
    }
    printf("\n");
#endif
#else
    	for(i = 0; i< cnt; i++)
	{
		ret = ccp903_rsa2048_decrypt_nocrt(ccp903_fd, Rsa2048_c, 256, Rsa2048_n, 256, Rsa2048_d, 256, rsa_plain_dec, &rsa_plain_dec_len);
		if(ret != 1)
		{
			printf("rsa2048_decrypt_nocrt error\n");
		}
        }

#endif
}
void *rsa2048_verify_sign_nocrt_test(void *args)
{
	int i, ret = 0;
    	unsigned char rsa_e[256] = {0}, rsa_d[256] = {0}, rsa_n[256] = {0}, rsa_p[256] = {0}, rsa_q[256] = {0}, rsa_dp[256] = {0}, rsa_dq[256] = {0}, rsa_qInv[256] = {0};
    	unsigned int rsa_e_len = 256, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len, rsa_sign_len, rsa_ver_plain_len;
    	unsigned char rsa_plain[P2048_LEN] = {0}, rsa_sign[256] = {0}, rsa_ver_plain[256] = {0};
#ifndef SPEED_TEST
    	for(i = 0; i < P2048_LEN; i++)
    	{
		rsa_plain[i] = i;
    	}
#ifdef Debug
    printf("rsa2048_plain: ");
    for(i = 0; i < P2048_LEN; i++)
    {
	printf("%x ",rsa_plain[i]);
    }
    printf("\n");
#endif
    	for(i = 256; i > 256-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[256 - i];
    	}
#ifdef Debug
    printf("rsa2048_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
	ccp903_rsa2048_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
#ifdef Debug
    printf("rsa2048_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
    printf("rsa2048_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
    ccp903_rsa2048_sign_nocrt(ccp903_fd, rsa_plain, P2048_LEN, rsa_n, rsa_n_len, rsa_d, rsa_d_len, rsa_sign, &rsa_sign_len);
#ifdef Debug
    printf("rsa2048_sign: ");
    for(i = 0; i < rsa_sign_len; i++)
    {
	printf("%x ",rsa_sign[i]);
    }
    printf("\n");
#endif
    	for(i = 0; i< cnt; i++)
	{
		ccp903_rsa2048_verify(ccp903_fd, rsa_plain, P2048_LEN, rsa_e, rsa_e_len, rsa_n, rsa_n_len, rsa_sign, rsa_sign_len, rsa_ver_plain, &rsa_ver_plain_len);
        }
#ifdef Debug
    printf("rsa2048_ver_plain: ");
    for(i = 0; i < rsa_ver_plain_len; i++)
    {
	printf("%x ",rsa_ver_plain[i]);
    }
    printf("\n");
#endif
    if(!memcmp(rsa_plain,rsa_ver_plain,rsa_ver_plain_len))
    {
	printf("rsa2048 verify success!!\n");
    }
    else
    {
	printf("rsa2048 verify failed!!\n");
    }
#else

    	for(i = 0; i< cnt; i++)
	{
	        ret = ccp903_rsa2048_verify(ccp903_fd, Rsa2048_plain, 256, Rsa2048_e, rsa_e_len, Rsa2048_n, 256, Rsa2048_c, 256, rsa_ver_plain, &rsa_ver_plain_len);
		if(ret != 1)
		{
			printf("rsa2048_verify error\n");
		}
        }
#endif

}
void *rsa4096_decrypt_crt_test(void *args)
{
	int i;
    	unsigned char rsa_e[512] = {0}, rsa_d[512] = {0}, rsa_n[512] = {0}, rsa_p[512] = {0}, rsa_q[512] = {0}, rsa_dp[512] = {0}, rsa_dq[512] = {0}, rsa_qInv[512] = {0};
    	unsigned int rsa_e_len = 512, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len, rsa_plain_dec_len;
    	unsigned char rsa_plain[P4096_LEN] = {0}, rsa_c[512] = {0}, rsa_plain_dec[512] = {0};
    	for(i = 0; i < P4096_LEN; i++)
    	{
		rsa_plain[i] = i%256;
    	}
#ifdef Debug
    printf("rsa4096_plain: ");
    for(i = 0; i < P4096_LEN; i++)
    {
	printf("%x ",rsa_plain[i]);
    }
    printf("\n");
#endif
    	for(i = 512; i > 512-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[512 - i];
    	}
#ifdef Debug
    printf("rsa4096_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
	ccp903_rsa4096_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
	ccp903_rsa4096_encrpy(ccp903_fd, rsa_e, rsa_e_len, rsa_n, rsa_n_len, rsa_plain, P4096_LEN, rsa_c, &rsa_c_len);
#ifdef Debug
    printf("rsa4096_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
    printf("rsa4096_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
    printf("rsa4096_c: ");
    for(i = 0; i < rsa_c_len; i++)
    {
	printf("%x ",rsa_c[i]);
    }
    printf("\n");
#endif
    	for(i = 0; i< cnt; i++)
	{
		ccp903_rsa4096_decrypt_crt(ccp903_fd, rsa_c, rsa_c_len, rsa_n, rsa_n_len, rsa_p, rsa_p_len, rsa_q, rsa_q_len, rsa_dp, rsa_dp_len, rsa_dq, rsa_dq_len, rsa_qInv, rsa_qInv_len, rsa_plain_dec, &rsa_plain_dec_len);
        }
#ifdef Debug
    printf("rsa4096_plain_dec: ");
    for(i = 0; i < rsa_plain_dec_len; i++)
    {
	printf("%x ",rsa_plain_dec[i]);
    }
    printf("\n");
#endif
#ifdef Debug
    if(!memcmp(rsa_plain,rsa_plain_dec,rsa_plain_dec_len))
    {
	printf("rsa4096 dec success!!\n");
    }
    else
    {
	printf("rsa4096 dec failed!!\n");
    }
#endif
}
void *rsa4096_verify_test(void *args)
{
	int i;
    	unsigned char rsa_e[512] = {0}, rsa_d[512] = {0}, rsa_n[512] = {0}, rsa_p[512] = {0}, rsa_q[512] = {0}, rsa_dp[512] = {0}, rsa_dq[512] = {0}, rsa_qInv[512] = {0};
    	unsigned int rsa_e_len = 512, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len, rsa_sign_len, rsa_ver_plain_len;
    	unsigned char rsa_plain[P4096_LEN] = {0}, rsa_sign[512] = {0}, rsa_ver_plain[512] = {0};
    	for(i = 0; i < P4096_LEN; i++)
    	{
		rsa_plain[i] = i;
    	}
#ifdef Debug
    printf("rsa4096_plain: ");
    for(i = 0; i < P4096_LEN; i++)
    {
	printf("%x ",rsa_plain[i]);
    }
    printf("\n");
#endif
    	for(i = 512; i > 512-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[512 - i];
    	}
#ifdef Debug
    printf("rsa4096_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
	ccp903_rsa4096_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
#ifdef Debug
    printf("rsa4096_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
    printf("rsa4096_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
    ccp903_rsa4096_sign_crt(ccp903_fd, rsa_plain, P4096_LEN, rsa_n, rsa_n_len, rsa_p, rsa_p_len, rsa_q, rsa_q_len, rsa_dp, rsa_dp_len, rsa_dq, rsa_dq_len, rsa_qInv, rsa_qInv_len, rsa_sign, &rsa_sign_len);
#ifdef Debug
    printf("rsa4096_sign: ");
    for(i = 0; i < rsa_sign_len; i++)
    {
	printf("%x ",rsa_sign[i]);
    }
    printf("\n");
#endif
    	for(i = 0; i< cnt; i++)
	{
		ccp903_rsa4096_verify(ccp903_fd, rsa_plain, P2048_LEN, rsa_e, rsa_e_len, rsa_n, rsa_n_len, rsa_sign, rsa_sign_len, rsa_ver_plain, &rsa_ver_plain_len);
        }
#ifdef Debug
    printf("rsa4096_ver_plain: ");
    for(i = 0; i < rsa_ver_plain_len; i++)
    {
	printf("%x ",rsa_ver_plain[i]);
    }
    printf("\n");
#endif
    if(!memcmp(rsa_plain,rsa_ver_plain,rsa_ver_plain_len))
    {
	printf("rsa4096 verify success!!\n");
    }
    else
    {
	printf("rsa4096 verify failed!!\n");
    }

}
void *rsa4096_decrypt_nocrt_test(void *args)
{
	int i;
    	unsigned char rsa_e[512] = {0}, rsa_d[512] = {0}, rsa_n[512] = {0}, rsa_p[512] = {0}, rsa_q[512] = {0}, rsa_dp[512] = {0}, rsa_dq[512] = {0}, rsa_qInv[512] = {0};
    	unsigned int rsa_e_len = 512, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len, rsa_plain_dec_len;
    	unsigned char rsa_plain[P4096_LEN] = {0}, rsa_c[512] = {0},rsa_plain_dec[512] = {0};
    	for(i = 0; i < P4096_LEN; i++)
    	{
		rsa_plain[i] = i;
    	}
#ifdef Debug
    printf("rsa4096_plain: ");
    for(i = 0; i < P4096_LEN; i++)
    {
	printf("%x ",rsa_plain[i]);
    }
    printf("\n");
#endif
    	for(i = 512; i > 512-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[512 - i];
    	}
#ifdef Debug
    printf("rsa4096_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
	ccp903_rsa4096_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
	ccp903_rsa4096_encrpy(ccp903_fd, rsa_e, rsa_e_len, rsa_n, rsa_n_len, rsa_plain, P4096_LEN, rsa_c, &rsa_c_len);
#ifdef Debug
    printf("rsa4096_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
    printf("rsa4096_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
    printf("rsa4096_c: ");
    for(i = 0; i < rsa_c_len; i++)
    {
	printf("%x ",rsa_c[i]);
    }
    printf("\n");
#endif
    	for(i = 0; i< cnt; i++)
	{
		ccp903_rsa4096_decrypt_nocrt(ccp903_fd, rsa_c, rsa_c_len, rsa_n, rsa_n_len, rsa_d, rsa_d_len, rsa_plain_dec, &rsa_plain_dec_len);
        }
#ifdef Debug
    printf("rsa4096_plain_dec: ");
    for(i = 0; i < rsa_plain_dec_len; i++)
    {
	printf("%x ",rsa_plain_dec[i]);
    }
    printf("\n");
#endif
}
void *rsa4096_verify_sign_nocrt_test(void *args)
{
	int i;
    	unsigned char rsa_e[512] = {0}, rsa_d[512] = {0}, rsa_n[512] = {0}, rsa_p[512] = {0}, rsa_q[512] = {0}, rsa_dp[512] = {0}, rsa_dq[512] = {0}, rsa_qInv[512] = {0};
    	unsigned int rsa_e_len = 512, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len, rsa_sign_len, rsa_ver_plain_len;
    	unsigned char rsa_plain[P4096_LEN] = {0}, rsa_sign[512] = {0}, rsa_ver_plain[512] = {0};
    	for(i = 0; i < P4096_LEN; i++)
    	{
		rsa_plain[i] = i;
    	}
#ifdef Debug
    printf("rsa4096_plain: ");
    for(i = 0; i < P4096_LEN; i++)
    {
	printf("%x ",rsa_plain[i]);
    }
    printf("\n");
#endif
    	for(i = 512; i > 512-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[512 - i];
    	}
#ifdef Debug
    printf("rsa4096_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
	ccp903_rsa4096_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
#ifdef Debug
    printf("rsa4096_n: ");
    for(i = 0; i < rsa_n_len; i++)
    {
	printf("%x ",rsa_n[i]);
    }
    printf("\n");
    printf("rsa4096_e: ");
    for(i = 0; i < rsa_e_len; i++)
    {
	printf("%x ",rsa_e[i]);
    }
    printf("\n");
#endif
    ccp903_rsa4096_sign_nocrt(ccp903_fd, rsa_plain, P4096_LEN, rsa_n, rsa_n_len, rsa_d, rsa_d_len, rsa_sign, &rsa_sign_len);
#ifdef Debug
    printf("rsa4096_sign: ");
    for(i = 0; i < rsa_sign_len; i++)
    {
	printf("%x ",rsa_sign[i]);
    }
    printf("\n");
#endif
    	for(i = 0; i< cnt; i++)
	{
		ccp903_rsa4096_verify(ccp903_fd, rsa_plain, P4096_LEN, rsa_e, rsa_e_len, rsa_n, rsa_n_len, rsa_sign, rsa_sign_len, rsa_ver_plain, &rsa_ver_plain_len);
        }
#ifdef Debug
    printf("rsa4096_ver_plain: ");
    for(i = 0; i < rsa_ver_plain_len; i++)
    {
	printf("%x ",rsa_ver_plain[i]);
    }
    printf("\n");
#endif
    if(!memcmp(rsa_plain,rsa_ver_plain,rsa_ver_plain_len))
    {
	printf("rsa4096 verify success!!\n");
    }
    else
    {
	printf("rsa4096 verify failed!!\n");
    }

}
void *sm2_genkey_test(void *args)
{
    int i;
    unsigned char wx[32], wy[32], privkey[32];
    int wxlen, wylen, privkeylen, rlen, slen;
    for(i = 0; i< cnt; i++)
    {
    	ccp903_sm2_keygen(ccp903_fd, wx, &wxlen, wy, &wylen, privkey, &privkeylen);
    }

    pthread_exit(NULL);
}
void *sm2_sign_test(void *args)
{
    int i, ret = 0;
    unsigned char wx[32], wy[32], privkey[32], r[32], s[32], hash[32];
    int wxlen, wylen, privkeylen, rlen, slen;
#ifndef SPEED_TEST
    ccp903_sm2_keygen(ccp903_fd, wx, &wxlen, wy, &wylen, privkey, &privkeylen);

    for(i = 0; i < cnt; i++)
    {
        ccp903_sm2_sign(ccp903_fd, hash, 32, privkey, privkeylen, r, &rlen, s, &slen);
    }
#else
    for(i = 0; i < cnt; i++)
    {
        ret = ccp903_sm2_sign(ccp903_fd, hash, 32, sm2_dec_key0 + 64, 32, r, &rlen, s, &slen);
	if(ret != 1)
	{
		printf("ccp903_sm2_sign error\n");
	}
    }

#endif
    pthread_exit(NULL);

}


void *sm2_verify_test(void *args)
{
    int i;
    unsigned char wx[32], wy[32], privkey[32], r[32], s[32], hash[32];
    int wxlen, wylen, privkeylen, rlen, slen;
#ifndef SPEED_TEST
    ccp903_sm2_keygen(ccp903_fd, wx, &wxlen, wy, &wylen, privkey, &privkeylen);
    ccp903_sm2_sign(ccp903_fd, hash, 32, privkey, privkeylen, r, &rlen, s, &slen);

    for(i = 0; i < cnt; i++)
    {
        ccp903_sm2_verify(ccp903_fd, hash, 32, r, rlen, s, slen, wx, wxlen, wy, wylen);
    }
#else
    for(i = 0; i < cnt; i++)
    {
        ccp903_sm2_verify(ccp903_fd, sm2_ver_id0, 32, sm2_ver_sigval0, 32, sm2_ver_sigval0+32, 32, sm2_ver_pubkey0, 32, sm2_ver_pubkey0+32, 32);
    }
#endif
    pthread_exit(NULL);

}
void *sm2_encrypt_test(void *args)
{
    int i;
    unsigned char wx[32], wy[32], privkey[32], c1[32], c2[32], c3[32];
    int wxlen, wylen, privkeylen, c1_len, c2_len, c3_len;
#ifndef SPEED_TEST
    ccp903_sm2_keygen(ccp903_fd, wx, &wxlen, wy, &wylen, privkey, &privkeylen);
    unsigned char mes[32]={0};
    for(i = 0; i < 32; i++)
    {
	mes[i] = rand();
    }

    for(i = 0; i < cnt; i++)
    {
	 ccp903_sm2_encrpy(ccp903_fd, mes,32, wx, wxlen, wy, wylen, c1, &c1_len, c2, &c2_len, c3, &c3_len);
    }
#ifdef Debug
    printf("c1: ");
    for(i = 0; i < c1_len; i++)
    {
	printf("%x ",c1[i]);
    }
    printf("\n");
    printf("c2: ");
    for(i = 0; i < c2_len; i++)
    {
	printf("%x ",c2[i]);
    }
    printf("\n");
    printf("c3: ");
    for(i = 0; i < c3_len; i++)
    {
	printf("%x ",c3[i]);
    }
    printf("\n");
#endif
#else
    for(i = 0; i < cnt; i++)
    {
	 ccp903_sm2_encrpy(ccp903_fd, sm2_dec_stddata0, 32, sm2_dec_key0, 32, sm2_dec_key0+32, 32, c1, &c1_len, c2, &c2_len, c3, &c3_len);
    }
#endif
    pthread_exit(NULL);

}
void *sm2_decrypt_test(void *args)
{
    int i;
    unsigned char wx[32], wy[32], privkey[32], c1[32*2+1], c2[32], c3[32];
    int wxlen, wylen, privkeylen, c1_len, c2_len, c3_len, mes_dec_len;
    unsigned char mes[32] = {0}, mes_dec[32] = {0};
#ifndef SPEED_TEST
    ccp903_sm2_keygen(ccp903_fd, wx, &wxlen, wy, &wylen, privkey, &privkeylen);
#ifdef Debug
    printf("unsigned char Sm2_privkey[32] = { \n");
    for(i = 0; i < privkeylen; i++)
    {
	printf("0x%x,",privkey[i]);
    }
    printf("\n};\n");
    printf("unsigned char Sm2_pub_wx[32] = { \n");
    for(i = 0; i < wxlen; i++)
    {
	printf("0x%x,",wx[i]);
    }
    printf("\n};\n");
    printf("unsigned char Sm2_pub_wy[32] = { \n");
    for(i = 0; i < wylen; i++)
    {
	printf("0x%x,",wy[i]);
    }
    printf("\n};\n");
#endif
    for(i = 0; i < 32; i++)
    {
	mes[i] = rand();
    }
#ifdef Debug
    printf("unsigned char Sm2_mes[32] = { \n");
    for(i = 0; i < 32; i++)
    {
	printf("0x%x,",mes[i]);
    }
    printf("\n};\n");
#endif
    ccp903_sm2_encrpy(ccp903_fd, mes, 32, wx, wxlen, wy, wylen, c1, &c1_len, c2, &c2_len, c3, &c3_len);
    printf("unsigned char Sm2_c1[65] = { \n");
    for(i = 0; i < c1_len; i++)
    {
	printf("0x%x,",c1[i]);
    }
    printf("\n};\n");
    printf("unsigned char Sm2_c2[32] = { \n");
    for(i = 0; i < c2_len; i++)
    {
	printf("0x%x,",c2[i]);
    }
    printf("\n};\n");
    printf("unsigned char Sm2_c3[32] = { \n");
    for(i = 0; i < c3_len; i++)
    {
	printf("0x%x,",c3[i]);
    }
    printf("\n};\n");
    for(i = 0; i < cnt; i++)
    {
	ccp903_sm2_decrypt(ccp903_fd, privkey, privkeylen, c1, c1_len, c2, c2_len, c3, c3_len, mes_dec, &mes_dec_len);
    }
#ifdef Debug
    printf("unsigned char mes_dec_org[32] = { \n");
    for(i = 0; i < 32; i++)
    {
	printf("0x%x,",mes_dec[i]);
    }
    printf("\n};\n");
#endif
#else
    for(i = 0; i < cnt; i++)
    {
	ccp903_sm2_decrypt(ccp903_fd, sm2_dec_key0 + 64, 32, sm2_dec_srcdata0, 65, sm2_dec_srcdata0 + 64, 32, sm2_dec_srcdata0+96, 32, mes_dec, &mes_dec_len);
    }
#endif
    pthread_exit(NULL);

}

void *rsa1024_decrypt_crt_standard_test(void *args)//speed
{
	int i,ret = 0;
    	unsigned int rsa_plain_dec_len;
    	unsigned char rsa_plain_dec[128] = {0};
	for(i = 0; i< cnt; i++)
	{
		ret = ccp903_rsa1024_decrypt_crt(ccp903_fd, Rsa1024_c, 128, Rsa1024_n, 128, Rsa1024_p, 128, Rsa1024_q, 128, Rsa1024_dp, 128, Rsa1024_dq, 128, Rsa1024_qInv, 128, rsa_plain_dec, &rsa_plain_dec_len);//n c
        	if(ret != 1)
		{
			printf("rsa1024_decrypt_crt_error\n");
		}
	}
#ifdef Debug
    printf("rsa1024_plain_dec: ");
    for(i = 0; i < rsa_plain_dec_len; i++)
    {
	printf("%x ",rsa_plain_dec[i]);
    }
    printf("\n");
#endif
}
void *rsa2048_decrypt_crt_standard_test(void *args)
{
	int i, ret = 0;
    	unsigned int rsa_plain_dec_len;
    	unsigned char rsa_plain_dec[256] = {0};
    	for(i = 0; i< cnt; i++)
	{
		//ret = ccp903_rsa2048_decrypt_crt(ccp903_fd, rsa2048_data_tmp, 256, Rsa2048_Priv_N, 256, Rsa2048_Priv_P, 128, Rsa2048_Priv_Q, 128, Rsa2048_Priv_dP, 128, Rsa2048_Priv_dQ, 128, Rsa2048_Priv_qInv, 128, rsa_plain_dec, &rsa_plain_dec_len);
		ret = ccp903_rsa2048_decrypt_crt(ccp903_fd, Rsa2048_c, 256, Rsa2048_n, 256, Rsa2048_p, 256, Rsa2048_q, 256, Rsa2048_dp, 256, Rsa2048_dq, 256, Rsa2048_qInv, 256, rsa_plain_dec, &rsa_plain_dec_len);
        	if(ret != 1)
		{
			printf("rsa2048_decrypt_crt error\n");
		}
		//printf("rsa2048_decrypt_crt i = %d\n",i);
	}
#ifdef Debug
    printf("rsa2048_plain_dec: ");
    for(i = 0; i < rsa_plain_dec_len; i++)
    {
	printf("%x ",rsa_plain_dec[i]);
    }
    printf("\n");
#endif
}
void *rsa2048_genkey_sign_decrypt_crt_test(void *args)
{
	int i, ret = 0;
    	unsigned char rsa_e[256] = {0}, rsa_d[256] = {0}, rsa_n[256] = {0}, rsa_p[256] = {0}, rsa_q[256] = {0}, rsa_dp[256] = {0}, rsa_dq[256] = {0}, rsa_qInv[256] = {0};
    	unsigned int rsa_e_len = 256, rsa_d_len, rsa_n_len, rsa_p_len, rsa_q_len, rsa_dp_len, rsa_dq_len, rsa_qInv_len, rsa_c_len, rsa_plain_dec_len;
    	unsigned char rsa_plain[P2048_LEN] = {0}, rsa_c[256] = {0},rsa_plain_dec[256] = {0};
    	for(i = 0; i < P2048_LEN; i++)
    	{
		rsa_plain[i] = i;
    	}
    	for(i = 256; i > 256-3; i--)//pubkey 65535
    	{
		((U8 *)rsa_e)[i-1] = key1_e[256 - i];
    	}
	ccp903_rsa2048_keygen(ccp903_fd, rsa_e, rsa_e_len, rsa_d, &rsa_d_len, rsa_n, &rsa_n_len, rsa_p, &rsa_p_len, rsa_q, &rsa_q_len, rsa_dp, &rsa_dp_len, rsa_dq, &rsa_dq_len, rsa_qInv, &rsa_qInv_len);
	ccp903_rsa2048_encrpy(ccp903_fd, rsa_e, rsa_e_len, rsa_n, rsa_n_len, rsa_plain, P2048_LEN, rsa_c, &rsa_c_len);
    	for(i = 0; i< cnt; i++)
	{
		ccp903_rsa2048_decrypt_crt(ccp903_fd, rsa_c, rsa_c_len, rsa_n, rsa_n_len, rsa_p, rsa_p_len, rsa_q, rsa_q_len, rsa_dp, rsa_dp_len, rsa_dq, rsa_dq_len, rsa_qInv, rsa_qInv_len, rsa_plain_dec, &rsa_plain_dec_len);
        }
#ifdef Debug
    printf("rsa_c_len = %d\n",rsa_c_len);
    printf("rsa_n_len = %d\n",rsa_n_len);
    printf("rsa_p_len = %d\n",rsa_p_len);
    printf("rsa_q_len = %d\n",rsa_q_len);
    printf("rsa_dp_len = %d\n",rsa_dp_len);
    printf("rsa_dq_len = %d\n",rsa_dq_len);
    printf("rsa_qInv_len = %d\n",rsa_qInv_len);
    printf("rsa_plain_dec_len = %d\n",rsa_plain_dec_len);
    printf("rsa2048_plain_dec: ");
    for(i = 0; i < rsa_plain_dec_len; i++)
    {
	printf("%x ",rsa_plain_dec[i]);
    }
    printf("\n");
#endif
#ifdef Debug
    if(!memcmp(rsa_plain,rsa_plain_dec,rsa_plain_dec_len))
    {
	printf("rsa2048 dec success!!\n");
    }
    else
    {
	printf("rsa2048 dec failed!!\n");
    }
#endif
}
int create_thread(int threadnum)
{
    int i = 0;
    int idn[1024];

    for (i = 0; i < threadnum; i++)
    {
        idn[i] = i;
        switch(op_test)
        {
	case 1:
            pthread_create(&thread[i], NULL, sm2_genkey_test, &idn[i]);
	    break;
        case 2:
            pthread_create(&thread[i], NULL, sm2_sign_test, &idn[i]);
            break;
        case 3:
            pthread_create(&thread[i], NULL, sm2_verify_test, &idn[i]);
            break;
        case 4:
            pthread_create(&thread[i], NULL, sm2_encrypt_test, &idn[i]);
            break;
        case 5:
            pthread_create(&thread[i], NULL, sm2_decrypt_test, &idn[i]);
            break;
	case 6:
            pthread_create(&thread[i], NULL, rsa1024_encrypt_test, &idn[i]);
	    break;
	case 7:
            pthread_create(&thread[i], NULL, rsa1024_decrypt_crt_test, &idn[i]);
	    break;
	case 8:
            pthread_create(&thread[i], NULL, rsa1024_sign_crt_test, &idn[i]);
	    break;
	case 9:
            pthread_create(&thread[i], NULL, rsa1024_verify_test, &idn[i]);
	    break;
	case 10:
            pthread_create(&thread[i], NULL, rsa2048_encrypt_test, &idn[i]);
	    break;
	case 11:
            pthread_create(&thread[i], NULL, rsa2048_decrypt_crt_test, &idn[i]);
	    break;
	case 12:
            pthread_create(&thread[i], NULL, rsa2048_sign_crt_test, &idn[i]);
	    break;
	case 13:
            pthread_create(&thread[i], NULL, rsa2048_verify_test, &idn[i]);
	    break;
	case 14:
            pthread_create(&thread[i], NULL, rsa1024_decrypt_nocrt_test, &idn[i]);
	    break;
	case 15:
            pthread_create(&thread[i], NULL, rsa1024_verify_sign_nocrt_test, &idn[i]);
	    break;
	case 16:
            pthread_create(&thread[i], NULL, rsa2048_decrypt_nocrt_test, &idn[i]);
	    break;
	case 17:
            pthread_create(&thread[i], NULL, rsa2048_verify_sign_nocrt_test, &idn[i]);
	    break;
	case 18:
            pthread_create(&thread[i], NULL, rsa1024_genkey_test, &idn[i]);
	    break;
	case 19:
            pthread_create(&thread[i], NULL, rsa2048_genkey_test, &idn[i]);
	    break;
	case 20:
            pthread_create(&thread[i], NULL, rsa2048_decrypt_crt_standard_test, &idn[i]);
	    break;
	case 21:
            pthread_create(&thread[i], NULL, rsa1024_decrypt_crt_standard_test, &idn[i]);
	    break;
	case 22:
            pthread_create(&thread[i], NULL, rsa2048_genkey_sign_decrypt_crt_test, &idn[i]);
	    break;
	case 23:
            pthread_create(&thread[i], NULL, rsa4096_verify_test, &idn[i]);
	    break;
	case 24:
            pthread_create(&thread[i], NULL, rsa4096_decrypt_nocrt_test, &idn[i]);
	    break;
	case 25:
            pthread_create(&thread[i], NULL, rsa4096_verify_sign_nocrt_test, &idn[i]);
	    break;
	case 26:
            pthread_create(&thread[i], NULL, rsa4096_decrypt_crt_test, &idn[i]);
	    break;
        default:
            break;

        }
    }

    for (i = 0; i < threadnum; i++)
        pthread_join(thread[i], NULL);

    return i;
}

#if 0
int main(int argc, char *argv[])
{

    struct	timeval	tm1, tm2;
    float		speed;
    time_t 		dtime;


    if (argc < 4)
    {
        printf("*******************************************************************************\n");
        printf("*  usage: %s [thread number] [cnt times] [select]*\n", argv[0]);
        printf("*  default: thread number = 1, cnt times = 1 select = 1             *\n");
        printf("*******************************************************************************\n\n");
        if(argc == 1)
        {
            cnt = 1;
            threadnum = 1;
            op_test = 1;
        }
        else
        {
            return 0;
        }
    }
    else
    {
        op_test = atoi(argv[3]);
        cnt = atoi(argv[2]);
        threadnum = atoi(argv[1]);
    }

    ccp903_fd = open("/dev/csec", O_RDWR);
    if(ccp903_fd < 0)
    {
        printf("open dev csec error\n");
        return -1;
    }


    gettimeofday(&tm1, NULL);
    create_thread(threadnum);
    gettimeofday(&tm2, NULL);
    dtime = (tm2.tv_sec - tm1.tv_sec) * 1000000 + (tm2.tv_usec - tm1.tv_usec);
    speed = 1.0 * cnt * 1000000 * threadnum / dtime;

    printf("op_test = %d , speed : %8.0f times per sec!\n", op_test, speed);


    close(ccp903_fd);

    return 0;

}

#else //SPEED TEST
int main(int argc, char *argv[])
{

    struct	timeval	tm1, tm2;
    float		speed;
    time_t 		dtime;
    printf("*******************************************************************************\n");
    printf("*  usage: %s [thread number] [cnt times] [select]*\n", argv[0]);
    printf("*  default: thread number = 32, cnt times = 20 select = 1-23             *\n");
    printf("*******************************************************************************\n\n");
    cnt = 10;
    threadnum = 10;
    op_test = 0;

    ccp903_fd = open("/dev/csec", O_RDWR);
    if(ccp903_fd < 0)
    {
        printf("open dev csec error\n");
        return -1;
    }

    for(op_test = 1; op_test < 20; op_test++)
    {
    	gettimeofday(&tm1, NULL);
    	create_thread(threadnum);
   	gettimeofday(&tm2, NULL);
   	dtime = (tm2.tv_sec - tm1.tv_sec) * 1000000 + (tm2.tv_usec - tm1.tv_usec);
   	speed = 1.0 * cnt * 1000000 * threadnum / dtime;
    	printf(" op_test = %d speed : %8.0f times per sec!\n",op_test, speed);
    }

    close(ccp903_fd);

    return 0;

}

/*
int main()
{

    int i;
    int idn[32];
    pthread_t thread[32];
    threadnum = 32;
    cnt = 10;
    ccp903_fd = open("/dev/csec", O_RDWR);
    if(ccp903_fd < 0)
    {
        printf("open dev csec error\n");
        return -1;
    }

    for(op_test = 0; op_test < 24; op_test++)
    {
        create_thread(threadnum);
    }
    for (i = 0; i < 1; i++)
        pthread_create(&thread[i], NULL, sm2_genkey_speed_test, &idn[i]);

    for (i = 0; i < 1; i++)
        pthread_join(thread[i], NULL);

    close(ccp903_fd);

    return 0;

}
*/
#endif
